package main

import (
	"fmt"
	"github.com/spf13/viper"
	"google.golang.org/grpc"
	"net"
	"user/config"
	"user/internal/handler"
	"user/internal/logic"
	"user/internal/repository"
)

func main() {
	config.InitConfig()
	repository.InitDB()

	server := grpc.NewServer()
	defer server.Stop()
	logic.RegisterUserServiceServer(server, handler.NewUserService())

	grpcAddress := viper.GetString("server.grpcAddress")
	listen, err := net.Listen("tcp", grpcAddress)
	if err != nil {
		panic(err)
	}

	err1 := server.Serve(listen)
	if err1 != nil {
		fmt.Printf("failed to serve : %v", err)
		return
	}
}
